package com.subject.shuati.domain.handler.subject;

import com.subject.shuati.common.enums.IsDeleteFlagEnum;
import com.subject.shuati.common.enums.SubjectInfoTypeEnum;
import com.subject.shuati.domain.covert.BriefSubjectConverter;
import com.subject.shuati.domain.entity.SubjectInfoBo;
import com.subject.shuati.domain.entity.SubjectOptionBo;
import com.subject.shuati.infra.basic.entity.SubjectBrief;
import com.subject.shuati.infra.basic.service.SubjectBriefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 简答题目的策略模式实现类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Autowired
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo) {
        System.out.println(subjectInfoBo);
        SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.BoConverterToEntity(subjectInfoBo);
        subjectBrief.setSubjectId(subjectInfoBo.getId().intValue());
        subjectBrief.setIsDeleted(IsDeleteFlagEnum.UN_DELETE.getCode());
        subjectBriefService.insert(subjectBrief);

    }

    @Override
    public SubjectOptionBo query(int subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBo subjectOptionBO = new SubjectOptionBo();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;

    }
}
